package com.example.service.impl;

import com.example.mapper.StudentMapper;
import com.example.pojo.Student;
import com.example.service.IStudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/10/19
 * @Version 1.0
 **/
@Service
public class StudentService implements IStudentService {
    @Resource
    private StudentMapper studentMapper;
    @Override
    public PageInfo<Student> findAll(int offset,int pagesize,String name) {
        System.out.println(".....search:"+name);
        PageHelper.startPage(offset,pagesize);
        return new PageInfo<>(this.studentMapper.findAll(name));
    }

    @Override
    public boolean save(Student student) {
        if(student.getId()==null || student.getId() == 0) {
            return this.studentMapper.add(student) == 1;
        }else{
            return this.studentMapper.update(student)==1;
        }
    }

    @Override
    public boolean delete(String ids) {
        String[] arr = ids.split(",");
        return this.studentMapper.del(arr) >= 1;
    }
}
